'use strict';

/**
 * 为用户表添加nickname字段
 */
module.exports = {
  up: async (queryInterface, Sequelize) => {
    // 检查字段是否已存在
    const tableInfo = await queryInterface.describeTable('user');
    
    if (!tableInfo.nickname) {
      // 添加nickname字段
      await queryInterface.addColumn('user', 'nickname', {
        type: Sequelize.STRING(32),
        allowNull: true,
        comment: '昵称',
        after: 'username' // 在username字段后添加
      });
      console.log('用户表添加nickname字段成功');
    } else {
      console.log('nickname字段已存在，跳过');
    }
  },

  down: async (queryInterface, Sequelize) => {
    // 回滚时删除nickname字段
    await queryInterface.removeColumn('user', 'nickname');
  }
}; 